<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <!-- <a-col :span="24">
            <a-form-model-item label="消息来源（群）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgGroup">
              <a-input v-model="model.msgGroup" placeholder="请输入消息来源（群）"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerName">
              <a-input v-model="model.customerName" placeholder="请输入客户名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户消息内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgText">
              <a-input v-model="model.msgText" placeholder="请输入客户消息内容"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="category">
              <j-dict-select-tag
                v-model="model.category"
                placeholder="请选择大类"
                dictCode="gjzdl"
                style="width:100%"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="消息类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="msgtype">
              <a-input v-model="model.msgtype" placeholder="请输入消息类型"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNo">
              <a-input v-model="model.orderNo" placeholder="请输入订单号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="供应商回复内容"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="supplierReply"
            >
              <a-input v-model="model.supplierReply" placeholder="请输入供应商回复内容"></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="确认回复内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comfirmReply">
              <a-textarea
                v-model="model.comfirmReply"
                placeholder="请输入确认回复内容"
                :rows="10"
                allowClear
              ></a-textarea>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="回复时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="replyTime">
              <j-date placeholder="请选择回复时间" v-model="model.replyTime" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="回复人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="replyer">
              <a-input v-model="model.replyer" placeholder="请输入回复人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否完成" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isComplete">
              <a-select placeholder="请选择是否完成" v-model="model.isComplete" allowClear>
                <a-select-option value="是">是</a-select-option>
                <a-select-option value="否">否</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskState">
              <a-select placeholder="请选择处理状态" v-model="model.taskState" allowClear>
                <a-select-option value="已处理">已处理</a-select-option>
                <a-select-option value="未处理">未处理</a-select-option>
                <a-select-option value="人工介入">人工介入</a-select-option>
                <a-select-option value="处理中">处理中</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'TasklsitForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/tasklsit/tasklsit/add',
        edit: '/tasklsit/tasklsit/edit',
        queryById: '/tasklsit/tasklsit/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.model.comfirmReply = JSON.parse(JSON.stringify(this.model.supplierReply))
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>
